package org.jeecg.modules.phone.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.phone.entity.PhoneAccountTaskJoinTaskVo;
import org.jeecg.modules.phone.entity.PhoneEntity;
import org.jeecg.modules.phone.entity.PhoneEntityTaskRsource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.phone.entity.PhoneEntityTaskRsourceVo;

/**
 * @Description: 资源管理
 * @Author: jeecg-boot
 * @Date:   2022-08-31
 * @Version: V1.0
 */
public interface PhoneEntityTaskRsourceMapper extends BaseMapper<PhoneEntityTaskRsource> {
    @Select("SELECT r.*,e.entity_name,e.entity_status,e.tag,  t.task_name\n" +
            "FROM phone_entity_task_resource r\n" +
            "LEFT JOIN phone_entity e on r.entity_id=e.id\n" +
            "LEFT JOIN phone_task t on r.task_id= t.id " +
            "${ew.customSqlSegment}")
    IPage<PhoneEntityTaskRsourceVo> pageList(Page<PhoneEntityTaskRsourceVo> page,
                                             @Param(Constants.WRAPPER) Wrapper<PhoneEntityTaskRsourceVo> queryWrapper);




    @Update("UPDATE phone_entity_task_resource  \n" +
            "SET  resource_status = 0\n" +
            "WHERE  entity_id = '${entityId}'")
    void resetStatus(String entityId);

    @Select("SELECT e.*\n" +
            "FROM phone_entity  e\n" +
            "LEFT JOIN phone_entity_task_resource r on r.entity_id=e.id\n" +
            "${ew.customSqlSegment}")
    List<PhoneEntity> checkRunning(@Param(Constants.WRAPPER) Wrapper<PhoneEntityTaskRsource> phoneEntityTaskRsourceQueryWrapper);
}
